/**
 * 
 */
package org.leaves.mailsend.mail;

/**
 * @author chen
 * 
 */
public class MailThread extends Thread {
	private boolean state = true;

	@Override
	public void run() {
		MailQueue mq = new MailQueue();
		while (state) {
			System.out.println(mq.size());
			if (mq.isEmpty()) {
				SMTPClient sc = new SMTPClient();
				MailMessage message = (MailMessage) mq.get();
				sc.setMessage(message);
				int i = 0;
				while (i < 5) {
					if (sc.send()) {
						break;
					}
				}
			}
			try {
				sleep(10000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public void stopthreak() {
		this.state = false;
	}

}
